package edu.towson.cosc603.coffeemaker;

import junit.framework.TestCase;

/**
 * Test case for the CoffeeMaker class.
 */
public class CoffeeMakerTest extends TestCase
{

	private CoffeeMaker cm;

	private Inventory i;

	private Recipe r1;



	/**
	 * Sets up the fixture for the test.
	 * 
	 * @see junit.framework.TestCase#setUp()
	 */
	public void setUp()
	{
		cm = new CoffeeMaker();
		i = cm.checkInventory();

		r1 = new Recipe();
		r1.setName("Coffee");
		r1.setPrice(50);
		r1.setAmtCoffee(6);
		r1.setAmtMilk(1);
		r1.setAmtSugar(1);
		r1.setAmtChocolate(0);
	}



	/**
	 * Tests the add recipe method.
	 */
	public void testAddRecipe1()
	{
		assertTrue(cm.addRecipe(r1));
	}



	/**
	 * Tests the delete recipe method.
	 */
	public void testDeleteRecipe1()
	{
		cm.addRecipe(r1);
		assertTrue(cm.deleteRecipe(r1));
	}



	/**
	 * Tests the edit recipe method.
	 */
	public void testEditRecipe1()
	{
		cm.addRecipe(r1);
		Recipe newRecipe = new Recipe();
		newRecipe = r1;
		newRecipe.setAmtSugar(2);
		assertTrue(cm.editRecipe(r1, newRecipe));
	}



	/**
	 * Tests the CoffeMaker constructor.
	 */
	public void testCheckOptions0()
	{
		assertEquals(15, i.getChocolate());
		assertEquals(15, i.getCoffee());
		assertEquals(15, i.getMilk());
		assertEquals(15, i.getSugar());
	}



	/**
	 * Tests the add inventory method when it is successful.
	 */
	public void testAddInventory1()
	{
		assertTrue(cm.addInventory(4, 4, 4, 4));
	}



	/**
	 * Tests the add inventory method when a nonnegative number is added.
	 */
	public void testAddInventory1_E1()
	{
		assertFalse(cm.addInventory(4, -4, 4, 4));
	}



	/**
	 * Tests the check inventory method.
	 */
	public void testCheckInventory()
	{
		assertEquals(15, i.getChocolate());
		assertEquals(15, i.getCoffee());
		assertEquals(15, i.getMilk());
		assertEquals(15, i.getSugar());
	}



	/**
	 * Tests the make coffee method when enough money was entered.
	 */
	public void testPurchaseBeverage1()
	{
		assertEquals(0, cm.makeCoffee(r1, 50));
	}



	/**
	 * Tests the make coffee when the money entered was not enough.
	 */
	public void testPurchaseBeverage1_S2()
	{
		assertEquals(10, cm.makeCoffee(r1, 10));
	}



	/**
	 * Tests the add recipe method by trying to add a recipe which already
	 * exists.
	 */
	public void testAddRecipe1_E5()
	{
		Recipe r2 = r1;

		cm.addRecipe(r1);
		assertFalse(cm.addRecipe(r2));
	}



	/**
	 * Tests the make coffee method when there isn't enough ingredients in
	 * inventory.
	 */
	public void testPurchaseBeverage1_S1()
	{
		i.setCoffee(0);
		assertEquals(50, cm.makeCoffee(r1, 50));
	}



	/**
	 * Tests the get recipe for name method.
	 */
	public void testGetRecipeForName()
	{
		cm.addRecipe(r1);
		assertEquals(r1, cm.getRecipeForName("Coffee"));
	}



	/**
	 * Tests the add inventory method after adding items to the current
	 * inventory.
	 */
	public void testAddInventory1_AfterAdding()
	{
		cm.addInventory(5, 5, 5, 5);

		assertEquals(20, i.getChocolate());
		assertEquals(20, i.getCoffee());
		assertEquals(20, i.getMilk());
		assertEquals(20, i.getSugar());
	}



	/**
	 * Tests the check inventory method after making a purchase.
	 */
	public void testPurchaseBeverage1_AfterPurchase()
	{
		cm.makeCoffee(r1, 50);

		assertEquals(15, i.getChocolate());
		assertEquals(9, i.getCoffee());
		assertEquals(14, i.getMilk());
		assertEquals(14, i.getSugar());
	}

}